package com.sunsys.hbase.put.example;

import java.io.IOException;

import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.HTablePool;
import org.apache.hadoop.hbase.client.Put;

public class PutDemo {

	public PutDemo() {
	}
	
	public void insertDataIntoHTable(String tableName, String rowKey, String familyKey, String columnName, String columnValue) throws IOException {
		
		HTableInterface hTableInterface = null;
		HTablePool hTablePool = new HTablePool();
		
		/* get HTable instance associated with tableName */
		hTableInterface = hTablePool.getTable(tableName);
		
		/* create Put instance associated with key */
		Put put = new Put(rowKey.getBytes());
		/* add column family, column name and column value details */
		put.add(familyKey.getBytes(), columnName.getBytes(), columnValue.getBytes());
		
		/* insert into hTable */
		hTableInterface.put(put);
		System.out.println("inserted the data");
		
		hTableInterface.close();
		hTablePool.close();
	}
	
	public static void main(String []args) throws IOException {
	
		PutDemo put = new PutDemo();
		
		put.insertDataIntoHTable("users", "key1", "info", "col2", "col2_value1");
		put.insertDataIntoHTable("users", "key1", "info", "col3", "col3_value1");
		
		System.out.println("Thanks for using");
	}
}
